- count = 0
:ruby
  data = []
  data_crumbs = []
  issue = resource.issue

  resource.targets.each do |parameter|
    popup_content = []

    resource.inputs.each do |input|
      h = input.reglementary_status(parameter).first
      if h
        popup_content << { label: :dose.tl, value: h[1][:name] }
      end
    end

    popup_content << render('popup', product: parameter)

    shape = parameter.working_zone
    shape ||= parameter.product.shape(at: resource.started_at) if parameter.product
    if shape
      activity = parameter.best_activity if parameter.is_a?(InterventionTarget)
      if activity
        item = {
          name: parameter.product.name,
          shape: shape,
          activity: activity.name,
          shape_color: activity.color,
          popup: {header: true, content: popup_content}
        }
      else
        item = {
          name: parameter.product.name,
          shape: shape,
          activity: parameter.product.name,
          shape_color: cycle(theme_colors),
          popup: {header: true, content: popup_content}
        }
      end
      data << item
      count += 1
    end
  end
- map = visualization do |v|
  - if data.any?
    - v.serie :main, data
    - v.categories :activity, :main
  - if issue
    - v.serie :issue, [{name: issue.name, shape: issue.geolocation}]
    - v.points :issue.tl, :issue
  - resource.product_parameters.each do |cast|
    - if cast.crumbs.any?
      -# raise cast.crumbs.reorder(:read_at).collect{|c| c.metadata.symbolize_keys.merge(name: cast.name, point: [c.geolocation.y, c.geolocation.x])}.inspect
      :ruby
        infos = {:right_flow => "Débit droit", :left_flow => "Débit gauche", :wind_speed => "Vitesse du vent", :tank_level => "Niveau de la cuve"}
        data = cast.crumbs.reorder(:read_at).collect do |c|
          infos.keys.inject({}) do |h,k|
            h[k] = Measure.new(c.metadata[k.to_s]).to_f
            h
          end.merge(name: cast.name, shape: c.geolocation, width: 12)
        end
      - v.serie "crumb_#{cast.id}", data
      - infos.each do |info, label|
        - if params[:heatmap].to_i > 0
          - v.heatmap "heatmap_#{info}", "crumb_#{cast.id}", reference: info.to_s.camelcase(:lower), label: label + " (Heatmap)"
        - if params[:heatmap].to_i <= 0 or params[:band].to_i > 0
          - v.band    "band_#{info}", "crumb_#{cast.id}", reference: info.to_s.camelcase(:lower), label: label + " (Bande)"
      -# v.heatmap (cast.actor ? cast.actor.name : cast.variant ? cast.variant.name : cast.name), "heatmap_#{cast.id}", reference: :leftFlow
      - count += 1
  - v.control :zoom
  - v.control :scale
  - v.control :fullscreen
  - v.control :layer_selector
- if count > 0
  - cobbler.cobble :resource_map, title: :map do
    = map
